import {createRouter, createWebHistory} from 'vue-router'
import Home from '../views/Home.vue'
import List from "@/views/List.vue";
import Search from "@/views/Search.vue";
import Login from "@/views/Login.vue";
import UserInfo from "@/views/UserInfo.vue";
import {infoStore} from "@/store";

const routes = [
    {
        path: '/',
        name: 'home',
        component: Home
    },
    {
        path: '/list',
        name: 'List',
        component: List
    },
    {
        path: '/search',
        name: 'Search',
        component: Search
    },
    {
        path: '/login',
        name: 'Login',
        component: Login
    },
    {
        path: '/userInfo',
        name: 'UserInfo',
        component: UserInfo,
        beforeEnter: (to, from, next) => {
            const store = infoStore()
            if (store.isLogin) {
                next()
            } else {
                next('/login')
            }
        }
    },
]

const router = createRouter({
    history: createWebHistory(process.env.BASE_URL),
    routes
})

router.beforeEach((to, from) => {
    const store = infoStore()
    if (to.path === '/login' || to.path === '/userInfo') {
        store.updateIsFooterShow(false)
    } else store.updateIsFooterShow(true)
})
export default router
